
// import Home from '@/pages/Home'
// import Search from '@/pages/Search'
// import Login from '@/pages/Login'
// import Register from '@/pages/Register'
// import Detail from '@/pages/Detail'
// import AddCartSuccess from '@/pages/AddCartSuccess'
// import ShopCart from '@/pages/ShopCart'
// import Trade from '@/pages/Trade'
// import Pay from '@/pages/Pay'
// import PaySuccess from '@/pages/PaySuccess'
// import Center from '@/pages/Center'
// import MyOrder from '@/pages/Center/components/MyOrder'
// import GroupOrder from '@/pages/Center/components/GroupOrder'

const Home = () => import( '@/pages/Home')
const Search = () => import( '@/pages/Search')
const Login = () => import( '@/pages/Login')
const Register = () => import( '@/pages/Register')
const Detail = () => import( '@/pages/Detail')
const AddCartSuccess = () => import( '@/pages/AddCartSuccess')
const ShopCart = () => import( '@/pages/ShopCart')
const Trade = () => import( '@/pages/Trade')
const Pay = () => import( '@/pages/Pay')
const PaySuccess = () => import( '@/pages/PaySuccess')
const Center = () => import( '@/pages/Center')
const MyOrder = () => import( '@/pages/Center/components/MyOrder')
const GroupOrder = () => import( '@/pages/Center/components/GroupOrder')

import Communication from './communication-route'

export default [
  {
    ...Communication
  },
  {
    path: '/home',
    component: Home
  },
  {
    name: 'Search',
    path: '/search/:keyword?',// 加问号的目的是能够匹配到路由,参数该丢还是会丢失
    component: Search
    // 路由独享守卫
    // beforeEnter: (to, from, next) => {
    //   console.log('路由独享守卫')
    //   next()
    // }
  },
  {
    name:'Detail',
    path: '/detail/:goodsId?',
    component: Detail
  },
  {
    path: '/addCartSuccess/:skuNum?',
    component: AddCartSuccess,
    // path区分大小写(默认false)
    caseSensitive: true,
    beforeEnter: (to, from, next) => {
      if (to.params.skuNum && sessionStorage.getItem('GOODSINFO')) {
        next()
      } else {
        alert('必须携带商品数量和商品信息才可以访问该页面')
        next(false) // 不跳转,什么都不操作
      }
    }
  },
  {
    path: '/shopCart',
    component: ShopCart,
  },
  {
    path: '/trade',
    component: Trade,
    // 只有从购物车界面才能跳转到交易页面(/trade) (兼容一下login)
    beforeEnter: (to, from, next) => {
      if (from.path.includes('/shopcart')  || from.path.includes('/login')) {
        next()
      } else {
        alert('只能从购物车页面跳转交易页面')
        next(false)
      }
    }
  },
  {
    path: '/pay',
    component: Pay,
    // 只有从交易页面（创建订单）页面才能跳转到支付页面
    beforeEnter: (to, from, next) => {
      if ( from.path.includes('/trade') ) {
        next()
      } else {
        alert('只能从交易页面页面跳转支付页面')
        next(false)
      }
    }
  },
  {
    path: '/paysuccess',
    component: PaySuccess,
    // 只有从支付页面才能跳转到支付成功页面
    beforeEnter: (to, from, next) => {
      if ( from.path.includes('/pay') ) {
        next()
      } else {
        alert('只能从交易成功页面页面跳转支付页面')
        next(false)
      }
    }
  },
  {
    path: '/center',
    component:Center,
    children: [
      {
        // path: '/center/myorder',
        path: 'myorder',
        component: MyOrder
      },
      {
        path: 'grouporder',
        component: GroupOrder
      },
      {
        path: '',
        redirect:'myorder',
                  // /center/myorder
      }
    ]
  },
  {
    path: '/login',
    component: Login,
    meta: {
      isHide: true
    }
  },
  {
    path: '/register',
    component: Register,
    meta: {
      isHide: true
    }
  },
  {
    path: '/',
    redirect: '/home'
  },
]